package com.yanqu.road.entity.config.musicroom;


import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@FieldTypeAnnotation(tableName = "t_p_music_room_furniture", desc = "妙音坊 家具配置")
public class MusicRoomFurnitureConfig extends DataObject {

    @FieldTypeAnnotation(desc = "家具等级id", select = true)
    protected int id;
//    @FieldTypeAnnotation(desc = "产出舒适度")
//    protected String comfort = "";
//    @FieldTypeAnnotation(desc = "产出心情值")
//    protected String moodValue = "";
//    @FieldTypeAnnotation(desc = "产出饱食度")
//    protected String satiety = "";
//    @FieldTypeAnnotation(desc = "消耗舒适度")
//    protected String costComfort = "";
//    @FieldTypeAnnotation(desc = "消耗心情值")
//    protected String costMoodValue = "";
//    @FieldTypeAnnotation(desc = "消耗饱食度")
//    protected String costSatiety = "";
    @FieldTypeAnnotation(desc = "产出经验书")
    protected String produceExpBook = "";
    @FieldTypeAnnotation(desc = "产出应援物")
    protected String produceSupportItems = "";
    @FieldTypeAnnotation(desc = "繁荣度")
    protected int prosperity;
    @FieldTypeAnnotation(desc = "升级消耗")
    protected String cost;
    @FieldTypeAnnotation(desc = "等级所需繁荣度")
    protected int needProsperity;
    @FieldTypeAnnotation(desc = "标准家具等级")
    protected String standardGrade;
    @FieldTypeAnnotation(desc = "家具产出应援币")
    protected int gold;


//    protected Property comfortProp = new Property();
//
//    protected Property moodValueProp = new Property();
//
//    protected Property satietyProp = new Property();
//
//    protected Property costComfortProp = new Property();
//
//    protected Property costMoodValueProp = new Property();
//
//    protected Property costSatietyProp = new Property();

    /**
     * key 建筑id
     */
    protected Map<Integer, Property> costMap = new HashMap<>();

    private Map<Integer, List<List<Property>>> produceExpBookListMap = new HashMap<>();

    private Map<Integer, List<List<Property>>> produceSupportItemsMap = new HashMap<>();

    private Property standardGradeProp = new Property();

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

//    public String getComfort() {
//        return comfort;
//    }
//
//    public void setComfort(String comfort) {
//        this.comfort = comfort;
//        this.comfortProp = PropertyHelper.parseStringToProperty(comfort, "\\|");
//    }
//
//    public String getMoodValue() {
//        return moodValue;
//    }
//
//    public void setMoodValue(String moodValue) {
//        this.moodValue = moodValue;
//        this.moodValueProp = PropertyHelper.parseStringToProperty(moodValue, "\\|");
//        //策划需求有变动又要支持热更，特殊解析，key:888表示本级所需繁荣度 key:999表示本级的每时辰产出应援币
//    }
//
//    public String getSatiety() {
//        return satiety;
//    }
//
//    public void setSatiety(String satiety) {
//        this.satiety = satiety;
//        this.satietyProp = PropertyHelper.parseStringToProperty(satiety, "\\|");
//    }
//
//    public String getCostComfort() {
//        return costComfort;
//    }
//
//    public void setCostComfort(String costComfort) {
//        this.costComfort = costComfort;
//        this.costComfortProp = PropertyHelper.parseStringToProperty(costComfort, "\\|");
//    }
//
//    public String getCostMoodValue() {
//        return costMoodValue;
//    }
//
//    public void setCostMoodValue(String costMoodValue) {
//        this.costMoodValue = costMoodValue;
//        this.costMoodValueProp = PropertyHelper.parseStringToProperty(costMoodValue, "\\|");
//    }
//
//    public String getCostSatiety() {
//        return costSatiety;
//    }
//
//    public void setCostSatiety(String costSatiety) {
//        this.costSatiety = costSatiety;
//        this.costSatietyProp = PropertyHelper.parseStringToProperty(costSatiety, "\\|");
//    }

    public int getProsperity() {
        return prosperity;
    }

    public void setProsperity(int prosperity) {
        this.prosperity = prosperity;
    }

    public String getCost() {
        return cost;
    }

    public void setCost(String cost) {
//        this.cost = cost;
        Map<Integer, Property> tempCostMap = new HashMap<>();
        for (String s : cost.split("&")) {
            String[] split = s.split("-");
            int buildType = Integer.valueOf(split[0]);
            if (split.length > 1) {
                Property property = PropertyHelper.parseStringToProperty(split[1]);
                tempCostMap.put(buildType, property);
            }
        }
        this.costMap = tempCostMap;
    }

    public String getProduceExpBook() {
        return produceExpBook;
    }

    public void setProduceExpBook(String produceExpBook) {
//        this.produceExpBook = produceExpBook;
        for (String s : produceExpBook.split("&")) {
            String[] split = s.split("-");
            int buildId = Integer.valueOf(split[0]);
            List<List<Property>> list = PropertyHelper.parseNewStringToPropertyList(split[1]);
            produceExpBookListMap.put(buildId, list);
        }
    }

    public String getProduceSupportItems() {
        return produceSupportItems;
    }

    public void setProduceSupportItems(String produceSupportItems) {
//        this.produceSupportItems = produceSupportItems;
        for (String s : produceSupportItems.split("&")) {
            String[] split = s.split("-");
            int buildId = Integer.valueOf(split[0]);
            List<List<Property>> list = PropertyHelper.parseNewStringToPropertyList(split[1]);
            produceSupportItemsMap.put(buildId, list);
        }
    }

//    public Property getComfortProp() {
//        return new Property(comfortProp);
//    }
//
//    public Property getMoodValueProp() {
//        return new Property(moodValueProp);
//    }
//
//    public Property getSatietyProp() {
//        return new Property(satietyProp);
//    }
//
//    public Property getCostComfortProp() {
//        return new Property(costComfortProp);
//    }
//
//    public Property getCostMoodValueProp() {
//        return new Property(costMoodValueProp);
//    }
//
//    public Property getCostSatietyProp() {
//        return new Property(costSatietyProp);
//    }

    public Property getCost(int buildId) {
        if (!costMap.containsKey(buildId)) {
            return new Property();
        }
        return new Property(costMap.get(buildId));
    }

    public List<List<Property>> getProduceExpBooksList(int buildId) {
        List<List<Property>> list = new ArrayList<>();
        if (produceExpBookListMap.containsKey(buildId)) {
            list.addAll(produceExpBookListMap.get(buildId));
        }
        return list;
    }

    public List<List<Property>> getProduceSupportItemsList(int buildId) {
        List<List<Property>> list = new ArrayList<>();
        if (produceSupportItemsMap.containsKey(buildId)) {
            list.addAll(produceSupportItemsMap.get(buildId));
        }
        return list;
    }

    public int getNeedProsperity() {
        return needProsperity;
    }

    public void setNeedProsperity(int needProsperity) {
        this.needProsperity = needProsperity;
    }

    public String getStandardGrade() {
        return standardGrade;
    }

    public void setStandardGrade(String standardGrade) {
//        this.standardGrade = standardGrade;
        this.standardGradeProp = PropertyHelper.parseStringToProperty(standardGrade, "\\|");
    }

    public int getGold() {
        return gold;
    }

    public void setGold(int gold) {
        this.gold = gold;
    }

    /**
     * 建筑内的家具好评等级
     * @param buildId
     * @return
     */
    public int getStandardGradeLevelNeed(int buildId) {
        return this.standardGradeProp.getCountByGoodsId(buildId).intValue();
    }
}
